﻿<%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.Master" AutoEventWireup="true"
    Inherits="Wjtour.Web.Admin.picture.galleryaddedi" %>

<%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
<%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
<%@ Import Namespace="Wjtour.Domain" %>
<%@ Import Namespace="Wjtour.Common" %>
<%@ Import Namespace="Wjtour.Domain.dto" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        ul, li, p
        {
            margin: 0px;
            padding: 0px;
        }

        .picturebox
        {
            clear: both;
        }

            .picturebox ul
            {
                margin: 0px;
                padding: 0px;
            }

                .picturebox ul li
                {
                    float: left;
                    width: 180px;
                    height: 160px;
                    border: 3px solid #808080;
                    padding: 2px 2px 2px 2px;
                    margin: 5px 5px 5px 5px;
                    list-style: none;
                    background-color: #eef2fb;
                    text-align: center;
                }

        .picturebox li.coverbg
        {
            background-color: #ebde73;
        }

        .picturebox p
        {
            height: 23px;
            line-height:23px;
            text-align: left;
            padding-left: 10px;
            display: block;
        }

        .picturebox li img
        {
            border: 1px solid #efefef;
            width: 170px;
        }
        .picturebox span.pictitle
        {

        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">
    <table id="addeditable" border="1" cellpadding="0" cellspacing="0" bordercolor="#dddddd">
        <tr>
            <td width="115px" align="right">图库类别：
            </td>
            <td>&nbsp;<asp:DropDownList runat="server" ID="cid">
            </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td align="right">图库名称：
            </td>
            <td>&nbsp;<asp:TextBox ID="title" Width="300" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="right">图库描述：
            </td>
            <td>&nbsp;<asp:TextBox ID="gallerydesc" Width="300" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="right">上传图库图片：
            </td>
            <td>&nbsp;
                    <CuteWebUI:Uploader ID="Uploader1" runat="server" InsertButtonID="btnPublish" MultipleFilesUpload="true">
                    </CuteWebUI:Uploader>
                <asp:Button ID="btnPublish" runat="server" Text="添加图片" />
            </td>
        </tr>
        <tr>
            <td style="background-color: #e9f2fb" colspan="2">
                <div style="width: 100%" class="picturebox">
                    <ul>
                        <asp:Repeater ID="rptPreview" runat="server">
                            <ItemTemplate>
                                <li <%# GetCoverClass(Eval("iscover")) %>>
                                    <img src="<%# Eval("picturepath") %>" style="width: 156px; height: 106px;" />
                                    <p>
                                        <!--<span class="pictitle"  data-pictureid="<%# Eval("id") %>">图片名称:<%# Eval("picturetitle") %></span>-->
                                        <input type="hidden" id='pic_id_<%# Eval("id") %>' value="<%# Eval("id") %>" />
                                        <input type="hidden" id='pic_title_<%# Eval("id") %>' value="<%# Eval("picturetitle") %>" />
                                    </p>
                                    <p>
                                        <input type='button' value="移除" onclick="removepic(<%# Eval("id") %>)"/>&nbsp;
                                        <%
                                            var types = type.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries).ToList();
                                            if (types.Contains("1")
                                              || types.Contains("2")
                                              || types.Contains("3")
                                              || types.Contains("4"))
                                          { %>
                                        <input type='button' value="设为封面" onclick="setcover(<%# Eval("id") %>)"/>&nbsp;
                                        <%} %>
                                    </p>
                                </li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                </div>

            </td>
        </tr>
        <tr>
            <td align="right">&nbsp;
            </td>
            <td>&nbsp;<asp:Button ID="submit" runat="server" Text=" 保 存 " />
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".pictitle").click(function () {
                $(this).empty();
                var pid = $(this).data("pictureid");
                var title = $("#pic_title_" + pid).val();
                $(this).append("<input type='text' value='" + title + "' style='width:120px'/><img src='/admin/images/save.gif' alt='保存' style='width:23px;height:22px;cursor:pointer;vertical-align:middle' onclick='updatetitle("+pid+")'/>");
            });
        });

        function updatetitle(picid)
        {
            var el = event.target || event.srcElement;
            var title = $(el).prev().val();
            $.ajax({
                url: '/admin/ajax/PictureHandler.ashx',
                data: { 'type': 'updatetitle', 'picid': picid, 'title': title },
                dataType: 'json',
                success: function (d) {
                    if (d.Errcode != "0") {
                        alert(d.Errmsg);
                    } else {
                        window.location.reload();
                    }
                },
                error: function () {

                }
            });
        }

        function setcover(picid) {
            if(picid==0)
            {
                alert("请先保存图片！");
                return;
            }
            $.ajax({
                url: '/admin/ajax/PictureHandler.ashx',
                data: { 'type': 'setcover', 'picid': picid },
                dataType: 'json',
                success: function (d) {
                    if (d.Errcode != "0") {
                        alert(d.Errmsg);
                    } else {
                        window.location.reload();
                    }
                },
                error: function () {

                }
            });
        }

        function removepic(picid) {
            $.ajax({
                url: '/admin/ajax/PictureHandler.ashx',
                data: { 'type': 'removepic', 'picid': picid },
                dataType: 'json',
                success: function (d) {
                    if (d.Errcode != "0") {
                        alert(d.Errmsg);
                    } else {
                        window.location.reload();
                    }
                },
                error: function () {

                }
            });
        }
    </script>
</asp:Content>
